import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig(async () => ({
  plugins: [react()],

  // 配置代理
  server: {
    proxy: {
      '/api': {
        target: 'https://netdata.aqilmini.com',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path.replace(/^\/api/, '/api')
      }
    }
  },

  // 配置 npm 镜像源
  optimizeDeps: {
    include: ['react', 'react-dom', 'react-router-dom', 'antd'],
  },

  // 添加 CSS 预处理配置
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true, // 支持 antd@4 的样式
      },
    },
  },

  // Vite 2.6.0 以上需要配置
  clearScreen: false,
}))
